package com.yzpc.controller;
import com.yzpc.entity.MouseClick;
import com.yzpc.entity.Script;
import com.yzpc.service.Impl.MouseClickService;
import com.yzpc.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/click")
//处理跨域问题
@CrossOrigin(origins = {
        "https://mooc1-1.chaoxing.com",
        "https://mooc2-ans.chaoxing.com",
        "https://mooc1.chaoxing.com/"
},
        allowedHeaders = "*",
        allowCredentials = "true")
public class MouseClickController {
    @Autowired
    private MouseClickService mouseClickService;

    @PostMapping("/insert")
    public R recordClicks(@RequestBody MouseClick click) {
        int rtn = mouseClickService.saveClick(click);
        if (rtn > 0) {
            return R.success();
        } else {
            return R.error();
        }
    }

    @GetMapping("/coordinates")
    @ResponseBody
    public List<MouseClick> getMouseCoordinates() {
        return mouseClickService.getMouseClicks();
    }
}